import { ElNotification } from "element-plus"
import type { NotificationHandle } from "element-plus"

export const computedUnitSize = (size: any) => {
    if(size >= 1024 * 1024* 1024){
    return (size / 1024 / 1024/1024).toFixed(2) + "GB";
    }else if (size >= 1024 * 1024) {
       return (size / 1024 / 1024).toFixed(2) + "MB";
    } else if (size >= 1024) {
        return (size / 1024).toFixed(2) + "KB";
    } else {
        return size + "B";
    }
};

/**
 * 封装elm的提示组件
 * @param type 提示类型
 * @param message 内容
 * @param title 标题
 * @returns 
 */
export const ElNotificationFn = (type:string, message:string, title?:string):NotificationHandle =>{
    // 默认配置
    let options = {
        title: title || resolveTitle(type),
        message,
        type: resolveType(type),
        offset: 60,
        duration: 3000,
        dangerouslyUseHTMLString: false,
        customClass: 'tech-notification',
        onClose: () => {}
    }
    
    // 创建通知
    const notification = ElNotification(options);
    
    // 添加装饰元素
    setTimeout(() => {
        const notificationEl = document.querySelector('.tech-notification');
        if (notificationEl) {
            // 添加角落装饰
            const corners = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
            corners.forEach(position => {
                const corner = document.createElement('div');
                corner.className = `corner-decoration ${position}`;
                notificationEl.appendChild(corner);
            });
            
            // 添加侧边光效
            const sideBeam = document.createElement('div');
            sideBeam.className = 'side-beam';
            notificationEl.appendChild(sideBeam);
        }
    }, 0);
    
    return notification;
}

/**
 * 解析标题
 * @param type 类型
 * @returns 返回标题
 */
function resolveTitle(type:string){
    switch(type){
        case 'success': return '成功';
        case 'error': return '错误';
        case 'warning': return '警告';
        case 'info': return '信息';
        default: return '信息';
    }
}

/**
 * 解析类型
 * @param type 类型
 * @returns 返回类型
 */
function resolveType(type:string):any{
    switch(type){
        case 'success': return 'success';
        case 'error': return 'error';
        case 'warning': return 'warning';
        case 'info': return 'info';
        default: return 'info';
    }
}